package com.ksyun.timeservice.controller;

import com.ksyun.timeservice.domain.dto.ServiceInstance;
import com.ksyun.timeservice.domain.dto.TimeResponse;
import com.ksyun.timeservice.service.TimeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class TimeController {
    private final TimeService timeService;
    @GetMapping("/getDateTime")
    public ResponseEntity<TimeResponse> getDateTime(@RequestParam(value = "style",required = false) String style){
        String result=timeService.getCurrentDateTime(style);
        String serviceId= timeService.getServiceID();
        TimeResponse response=new TimeResponse(result,serviceId);
        return ResponseEntity.ok(response);
    }
    //唤醒操作
    @PostMapping("/awake")
    public ResponseEntity<ServiceInstance> awake(@RequestBody ServiceInstance serviceInstance){
        timeService.awake(serviceInstance);
        return ResponseEntity.ok(serviceInstance);
    }
    //睡眠操作
    @PostMapping("/sleep")
    public ResponseEntity<ServiceInstance> sleep(@RequestBody ServiceInstance serviceInstance){
        timeService.sleep(serviceInstance);
        return ResponseEntity.ok(serviceInstance);
    }

}
